﻿using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using Vanfa.Entities.User;

namespace Vanfa.Web.UI
{
    public abstract class BasePage : Page
    {
        /// <summary>
        /// 票据名称
        /// </summary>
        private const string UserTicketName = "User";

        protected vUserTicket UserData
        {
            get
            {
                var hct = HttpContext.Current;
                var data = hct.Session[UserTicketName] as vUserTicket;
                return data;
            }
        }

        /// <summary>
        /// 生成票据
        /// </summary>
        /// <param name="t"></param>
        protected void CreateTicket(vUserTicket t)
        {
            var hct = HttpContext.Current;
            hct.Session[UserTicketName] = t;
        }

        /// <summary>
        /// 默认登录页面
        /// </summary>
        protected string DefaultLoginURL
        {
            get
            {
                return ConfigurationManager.AppSettings["defaultLoginURL"] ?? "/index.aspx";
            }
        }

        protected override void OnLoad(EventArgs e)
        {
            if (UserData == null)
            {
                var ctx = HttpContext.Current;
                var sUrl = ctx.Request.RawUrl;
                HttpContext.Current.Response.Redirect("/index.aspx?returl=" + ctx.Server.UrlEncode(sUrl));
                HttpContext.Current.Response.End();
            }
            base.OnLoad(e);
        }
    }
}
